﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DARE.Save.DataStructures
{
    public class CCameraMgrData : ISaveData
    {
        public string ActiveCamera;
        public List<CCameraData> RenderCameras = new List<CCameraData>();
        public List<CCameraData> GameCameras = new List<CCameraData>();

        public void FillDataStructure(object camMgr)
        {
            CCameraMgr cameraMgr = camMgr as CCameraMgr;
            if (cameraMgr.ActiveCamera != null)
                ActiveCamera = cameraMgr.ActiveCamera.Name;
            foreach (CCamera cam in cameraMgr.GetGameCamerasList())
            {
                CCameraData camData = CDataStructuresMgr.Instance.SaveItem(cam) as CCameraData;
                GameCameras.Add(camData);
            }
            foreach (CCamera cam in cameraMgr.RenderCameras.Values)
            {
                CCameraData camData = CDataStructuresMgr.Instance.SaveItem(cam) as CCameraData;
                RenderCameras.Add(camData);
            }
        }

        public void FillFromDataStructure(out object cameraMgr, params object[] paramsData)
        {
            cameraMgr = new CCameraMgr();
            foreach (CCameraData camData in RenderCameras)
            {
                object cam;
                camData.FillFromDataStructure(out cam, paramsData);
                if (cam != null && !(cameraMgr as CCameraMgr).RenderCameras.ContainsKey((cam as CCamera).Name))
                    (cameraMgr as CCameraMgr).RenderCameras.Add((cam as CCamera).Name, cam as CCamera);
            }
            foreach (CCameraData camData in GameCameras)
            {
                object cam;
                camData.FillFromDataStructure(out cam, paramsData);
                if (cam != null)
                    (cameraMgr as CCameraMgr).RegisterCamera(cam as CCamera);
            }
            (cameraMgr as CCameraMgr).ActiveCamera = (cameraMgr as CCameraMgr).GetCamera(ActiveCamera);
        }
    }
}
